#ifndef _SAFE_STACK_H
#define _SAFE_STACK_H

#include "config.h"
#include "utility/Mutex.h"

namespace KCore
{

template<typename T>
class SafeStack
{
public:
	void Push(T p) 
	{
		MutexLock lock(&m_mutex);
		m_stack.push_back(p);
	};

	bool Pop(T& p) 
	{		
		MutexLock lock(&m_mutex);
		if (m_stack.empty())
			return false;

		p = m_stack.back();
		m_stack.pop_back();	
		return true;
	};
	
	void Clear(){m_stack.clear();}
	bool Empty(){return m_stack.empty();}
	
private:
	Mutex m_mutex;
	std::deque<T> m_stack;
};

}

#endif